﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.SystemManage.WebPages.Module
{
    public partial class ModuleIntroduce : System.Web.UI.Page
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        School.ModuleIntroduce moduleintro = null;
        byte category = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            category = byte.Parse(Request.QueryString["category"]);
            moduleintro = db.ModuleIntroduce.FirstOrDefault(m => m.Categories == category);

            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            
            if (moduleintro != null)
            {
                lblName.Text = lblSubNav.Text = db.SubMenu.FirstOrDefault(s => s.Categories == category).Name;
                editor.Value = moduleintro.Introduce;
            }
        }

        protected void btmSubmit_onclick(object sender, EventArgs e)
        {
            try
            {
                moduleintro.Introduce = editor.Value;
                if (db.SaveChanges() > 0)
                {
                    lblMsg.Text = "编辑成功！";
                }
                else
                {
                    lblMsg.Text = "编辑失败！";
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "编辑发生异常：" + ex.Message;
            }
        }
    }
}
